package com.hhh.Controller;

import com.hhh.Pojo.Orders;
import com.hhh.Pojo.Result;
import com.hhh.Service.OrderSerivce;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderSerivce orderSerivce;

    //    提交订单
//    提交订单
    @PostMapping("/submit")
    public Result Submit(@RequestBody Orders orders, HttpServletRequest request) {
        log.info("提交订单");
        orders.setUserId((Long) request.getSession().getAttribute("user"));
        orders.setCheckoutTime(LocalDateTime.now());
        // System.out.println(orders);
        return Result.success(orderSerivce.Insert(orders));
    }

    //    查询订单
//    查询订单
    @GetMapping("/userPage")
    public Result SelectPage(long page, long pageSize, HttpServletRequest request) {
        log.info("查询订单");
        long id = (long) request.getSession().getAttribute("user");
        return Result.success(orderSerivce.SelectPage(page, pageSize, id));
    }
}
